package com.bianguo.android.functiondemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;

import butterknife.ButterKnife;

public abstract class BaseListAdapter<T> extends BaseAdapter {

    protected Context mContext;
    protected ArrayList<T> list;
    protected LayoutInflater inflater;

    public BaseListAdapter(Context mContext, ArrayList<T> list) {
        this.mContext = mContext;
        this.list = list;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return  list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        return bindView(i, view, viewGroup);
    }

    public abstract View bindView(int position, View view, ViewGroup viewGroup);

    public static class BaseListHolder {

        public BaseListHolder(View itemView) {
            ButterKnife.bind(this, itemView);
        }
    }
}
